package com.example.jwtauthdemo.mapper;

import com.example.jwtauthdemo.entity.ClassUser;
import com.example.jwtauthdemo.entity.CreateClass;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface ClassMapper {

    //插入班级信息
    int insertClass(CreateClass createClass);

    //查询班级码，避免重复
    Integer selectClassCode(String classCode);

    CreateClass selectClassInfo(String classCode);
// 查询班级信息
    @Select("SELECT * FROM class WHERE teacher_id = #{teacherId}")
    List<CreateClass> selectClassesByTeacherId(@Param("teacherId") String teacherId);

    // 根据用户ID和角色查询关联的班级
    List<CreateClass> selectClassesByUserIdAndRole(@Param("userId") String userId, @Param("role") Integer role);

  //添加用户
    int insertClassUser(ClassUser classUser);

    @Delete("DELETE FROM class WHERE class_code = #{classCode}")
    int deleteClassByCode(@Param("classCode") String classCode);

    @Delete("DELETE FROM user_class_relation WHERE class_code = #{classCode}")
    int deleteUserClassRelations(@Param("classCode") String classCode);

}
